// 游学
layui.use(['jquery', 'element', 'table', 'layer', 'form', 'upload'], function(){
    var $ = layui.$;
    var schoolTable = layui.table;
    var ctxPath = "/education";

    schoolTable.render({
        id: 'schoolTableId',
        elem: '#schoolTableId',
        url: ctxPath + '/api/schoolGradeClass/list',
        page: true,
        method: 'post',
        cols:[[
            {field:'id', title:'ID', width: 50},
            {field:'schoolName', title:'学校', width: 200},
            {field:'grade', title:'年级', width: 100 },
            {field:'clazz', title:'班级', width: 100 },
            {field:'recommenders', title:'推荐人', width: 150 },
            {fixed:'right', title:'操作', width: 200, align:'center', toolbar: '#schoolBar'}
        ]],
        response: {
            statusName: 'returnCode' //数据状态的字段名称，默认：code
            ,statusCode: 0 //成功的状态码，默认：0
            ,msgName: 'returnMsg' //状态信息的字段名称，默认：msg
            ,countName: 'count' //数据总数的字段名称，默认：count
            ,dataName: 'data' //数据列表的字段名称，默认：data
        },
        done: function(res, curr, count){
            //如果是异步请求数据方式，res即为你接口返回的信息。
            //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
            console.log(res);

            //得到当前页码
            console.log(curr);

            //得到数据总量
            console.log(count);
        }
    });

    var active = {
        searchSchool: function(){
            var schoolName = $('#schoolName').val();
            var grade = $('#grade').val();
            var clazz = $('#clazz').val();
            schoolTable.reload('schoolTableId', {
                where: {
                    schoolName: schoolName,
                    grade: grade,
                    clazz: clazz
                }
            });
        },
        cancelBtn: function(e) {
            window.location.href = ctxPath + '/html/schoolGradeClass/schoolGradeClassList.html';
        }
    };

    //按钮事件
    $('.layui-btn').on('click', function(e){
        var type = $(this).data('type');
        active[type] ? active[type].call(this) : '';
    });

    //监听工具条
    schoolTable.on('tool(school)', function(obj){
        var data = obj.data ,layEvent = obj.event;
        if(layEvent === 'detail'){
            location.href = ctxPath + "/html/schoolGradeClass/viewSchoolGradeClass.html?id=" + data.id;
        } else if(layEvent === 'edit'){
            location.href = ctxPath + "/html/schoolGradeClass/formSchoolGradeClass.html?id=" + data.id;
        }
        return false;
    });


});
